import 'package:share_fit/app/models/base_model.dart';
import 'package:share_fit/app/tools/log_utils.dart';

class SleepDataSummary extends BaseModel {
  int sleepTimeSum = 0;

  /// 小时为单位
  int target = 0;
  late String startTime;
  late String endTime;

  /// 计算进度条需要的值
  get getProgressValue {
    int hours = sleepTimeSum ~/ 60;
    if (hours > target) {
      return 1.0;
    } else {
      return target <= 0.0 ? 0.0 : ((target - hours) / target).roundToDouble();
    }
  }

  @override
  bool from(Map<dynamic, dynamic> map) {
    try {
      List sleepList = map['list'];
      if (sleepList.isNotEmpty) {
        sleepTimeSum = sleepList.map((e) => e['sleepTime']).reduce((value, current) => value + current);
      }
    } catch (e, stack) {
      logger.d(e);
    }
    return true;
  }

  @override
  List<Object?> get props => [];
}
